<template>
  <div id="dialogPromotionList">
    <el-dialog
      title="商品货架列表"
      :visible.sync="dialogPromotionData.isShow"
      center
      width="55%"
    >
      <!-- 顶部搜索 -->
      <topSearch @toSearch="toSearch"></topSearch>
      <!-- 操作按钮 -->
      <div class="table-conBtn">
        <freshCom @searchList="searchList"></freshCom>
      </div>
      <!-- 表格部分 -->
      <el-table v-loading="loading" :data="tableData">
        <el-table-column
          label="商品编号"
          width="100"
          prop="goodsNo"
          align="center"
        >
        </el-table-column>
        <el-table-column
          label="商品基础名称"
          width="220"
          prop="goodsName"
          align="center"
        >
        </el-table-column>
        <el-table-column
          label="商品展示名称"
          width="220"
          prop="goodsDisplayName"
          align="center"
        >
        </el-table-column>
        <el-table-column label="商品类型" width="80" align="center">
          <template slot-scope="scope">
            {{
              scope.row.goodsType
                | filterName('live_room_window_commodity_type')
            }}
          </template>
        </el-table-column>
        <el-table-column label="所属学院" width="180" align="center">
          <template slot-scope="scope">
            {{ scope.row.school | filterName('sys_college') }}
          </template>
        </el-table-column>
        <el-table-column
          label="销售价"
          width="100"
          prop="salePrice"
          align="center"
        >
          <template slot-scope="{ row }">
            <span>{{ row.salePrice / 100 || '' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="100" align="center">
          <template slot-scope="scope">
            <el-button type="success" @click="checkedPromotion(scope.row)">
              选择
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页器 -->
      <pageCom
        :searchParams="searchParams"
        :total="total"
        @searchList="searchList"
      ></pageCom>
    </el-dialog>
  </div>
</template>

<script>
import { getPromotionList } from '@/api/system/window'
import { sysNormalDisable } from '@utils/dictionariesFunc'
import topSearch from '@component/system/window/commodity/topSearch'
export default {
  props: ['dialogPromotionData'],
  components: { topSearch },
  data() {
    return {
      loading: false,
      tableData: [],
      total: 0,
      searchParams: {
        pageNum: 1,
        pageSize: 10
      }
    }
  },
  async mounted() {
    this.searchList()
    await sysNormalDisable('sys_college', 'sys_college')
    await sysNormalDisable(
      'live_room_window_commodity_type',
      'live_room_window_commodity_type'
    )
  },
  methods: {
    // 列表
    searchList() {
      getPromotionList(this.searchParams, (res) => {
        this.total = res.total
        this.tableData = res.rows
      })
    },
    //搜索
    toSearch(val) {
      this.searchParams.pageNum = 1
      Object.assign(this.searchParams, val)
      this.searchList()
    },
    //选择
    checkedPromotion(row) {
      this.$emit('promotionInfo', row)
      this.dialogPromotionData.isShow = false
    }
  }
}
</script>

<style lang="less" scoped>
:deep(.el-dialog) {
  margin: 5vh auto 0 !important;
}
</style>
